home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / computerjanitor / plugins / unsupported_plugin.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.7 KB  |  100 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import computerjanitor
  6. import computerjanitorapp
  7. _ = computerjanitorapp.setup_gettext()
  8.  
  9. class UnsupportedPackagesPlugin(computerjanitor.Plugin):
  10.     '''Plugin to find packages no longer supported by Canonical.
  11.     
  12.     An unsupported package is one that is no longer available in the
  13.     archive.
  14.     
  15.     Unfortunately, this heuristic is unable to treat packages installed
  16.     manually (via dpkg), or from sources (such as PPAs) that are no longer
  17.     in sources.list.
  18.  
  19.     '''
  20.     description = _('Package is no longer supported: it is no longer in the package archive. (It may also have been installed from an unofficial archive that is no longer available. In that case you may want to keep it.)')
  21.     basenames = [
  22.         'linux-image',
  23.         'linux-headers',
  24.         'linux-image-debug',
  25.         'linux-ubuntu-modules',
  26.         'linux-header-lum',
  27.         'linux-backport-modules',
  28.         'linux-header-lbm',
  29.         'linux-restricted-modules']
  30.     
  31.     def __init__(self):
  32.         self.uname = os.uname()[2]
  33.  
  34.     
  35.     def is_current_kernel(self, pkg):
  36.         """Is pkg the currently running kernel or a related package?
  37.  
  38.         We don't want to remove the currently running kernel. The
  39.         kernel packages have names that start with the strings in
  40.         self.basenames, and end with the 'release' string from
  41.         os.uname.
  42.  
  43.         """
  44.         for base in self.basenames:
  45.             if pkg.name == '%s-%s' % (base, self.uname):
  46.                 return True
  47.         
  48.         return False
  49.  
  50.     
  51.     def installed_deps(self, pkg):
  52.         '''Return set of names of installed dependencies of a package.
  53.  
  54.         Only immediate dependencies, dependency graph is not traversed
  55.         deeply.
  56.  
  57.         '''
  58.         result = set()
  59.         for dep in pkg.installedDependencies:
  60.             for or_dep in dep.or_dependencies:
  61.                 result.add(or_dep.name)
  62.             
  63.         
  64.         return result
  65.  
  66.     
  67.     def has_installed_rdepends(self, cache, pkg):
  68.         '''Does a package have any installed reverse dependencies?'''
  69.         installed = _[1]
  70.         for x in installed:
  71.             if pkg.name in self.installed_deps(x):
  72.                 return True
  73.         
  74.         return False
  75.  
  76.     
  77.     def is_supported(self, pkg):
  78.         '''Is a package supported?'''
  79.         if not pkg.isInstalled:
  80.             return True
  81.         if pkg.installedDownloadable or pkg.candidateDownloadable:
  82.             return True
  83.         if len(pkg._pkg.VersionList) > 1:
  84.             return True
  85.         if self.is_current_kernel(pkg):
  86.             return True
  87.         return False
  88.  
  89.     
  90.     def get_cruft(self):
  91.         for pkg in self.app.apt_cache:
  92.             if not self.is_supported(pkg):
  93.                 if not self.has_installed_rdepends(self.app.apt_cache, pkg):
  94.                     yield computerjanitor.PackageCruft(pkg, self.description)
  95.                 
  96.             self.has_installed_rdepends(self.app.apt_cache, pkg)
  97.         
  98.  
  99.  
  100.